<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
<head>
<base href="<%=basePath%>" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="icon" type="image/png" href="i/buyu.ico">
<link rel="apple-touch-icon-precomposed" href="i/app-icon72x72@2x.png">
<meta name="apple-mobile-web-app-title" content="Amaze UI" />
<link rel="stylesheet" href="css/amazeui.min.css" />
<link rel="stylesheet" href="css/admin.css">
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="layui/css/layui.css">

<style type="text/css">
.layui-form-label {
	width: 200px;
}

.layui-input-block {
	margin-left: 130px;
	min-height: 36px
}
</style>
</head>
<%
	String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
%>
<%!int count = 0;%><!-- 定义全局变量 -->
<body data-type="generalComponents">
	<div class="tpl-portlet-components am-center">
		<form class="layui-form" action="" style="text-align: center" >
			<div class="layui-form-item" style="margin-top: 10px;">
				<div>
					<span>ID：</span><input name="userId" class="zid" readonly="readonly">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="font-size: 10px; margin-left:31%;">难度级别</label>
				<div class="layui-input-block">
					<div class="magicalcoder-tmp-wrap"
						style="width: 120px; float: left;">
						<select id="DifficultLevel" name="DifficultLevel">
							<option value="0">极难</option>
							<option value="1">很难 </option>
							<option value="2">难 </option>
							<option value="-1">取消控制 </option>
							<option value="4">容易 </option>
							<option value="5">很容易 </option>
							<option value="6">极易 </option>
						</select>
						<!-- <input type="hidden" id="Controlpoints" name="Controlpoints" value="" /> -->
					</div>
				</div>
			</div>
			<!-- <div class="layui-form-item">
				<label class="layui-form-label" style="font-size: 10px; margin-left:31%;">增加/降低捕鱼难度</label>
				<div class="layui-input-block">
					<div class="magicalcoder-tmp-wrap"
						style="width: 120px; float: left;" >
						<select id="ContrlDifficulty"  name="ContrlDifficulty">
							<option value="1">增加难度</option>
							<option value="2">降低难度 </option>
						</select>
					</div>
				</div>
			</div> -->
			<!-- <input type="hidden" id="Contrldifficulty" name="Contrldifficulty" value="" /> -->

			<!-- <label style="font-size: 10px; margin-left:-5%;">调整难度系数</label> -->
				<div class="layui-input-block">
			<div tabindex="0" hidefocus="true" id="slide" class="demo-slider"
				outline=0; onblur="sliderNumber()" style="display:none;"><!-- 增加onblur事件 -->
			</div>
			</div>
			<input type="hidden" id="slideNumber" name="slideNumber" value="" />
			<input type="hidden" id="Currency">
			<div class="layui-form-item" style="margin-top: 10px;">
			<div class="layui-inline" style="margin-bottom: 0px;">
					<label class="layui-form-label" style="height: 38px;padding:0px;margin-bottom: 5px;border-bottom-width: 20px;padding-top:10px">期望玩家赢(输)多少分</label>
					<div class="layui-input-inline" style="height:38px;">
					<input type="text" title="赢为正数，输为负数"  name="TargetFraction" class="targetFraction" id="TargetFraction" placeholder="输入期望分数" min="0" style="border:1px solid #c8cccf;width: 184px;height: 38px;" autocomplete="off">
				    </div>
				</div>
				<div class="layui-inline">
							<div class="layui-input-inline">
								<button class="layui-btn"  id="Transformation" lay-filter="Transformation">数字转换汉字</button>
							</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="save"  style="font-size: 10px; margin-left:-15%;">立即提交</button>
				</div>
			</div>
			<div class="layui-form-item" style="margin-top: 10px;">
				<div>
					<span style="display:inline-block;color:red">上下分请填入正数，取消控制填0</span>
				</div>
			</div>
		</form>
	</div>
	<script src="js/jquery.min.js"></script>
	<script src="layui/layui.js"></script>
	<script>
		layui.use([ 'slider', 'layer', 'form' ], function() {
			var slider = layui.slider;
			var layer = layui.layer;
			var form = layui.form;
			//开启输入框
			var silder_sta = slider.render({
				elem : '#slide',
				input : true //输入框
				,
				max : '50',
				change : function(value) {
					count = value;//定义了 全局变量count，并且把实时变量value的值赋给了count
				}
			});
			form.on('submit(save)',function(data){
				var number = 0;
				var re = /^[0-9]+[0-9]*]*$/; //判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/
				if(data.field['userId'] == ''){
					layer.msg("请确认用户名",{icon:2});
					return false;
				}else if(data.field.DifficultLevel != 0 && data.field['TargetFraction'] == ''){
					layer.msg("请输入玩家期望分数！！！",{icon:2});
					return false;
				}
				if(data.field.DifficultLevel < 0)
					number = -parseInt(data.field.TargetFraction) + parseInt($("#Currency").val());
				else if(data.field.DifficultLevel > 0)
					number = parseInt(data.field.TargetFraction) + parseInt($("#Currency").val());
				else{
					setTimeout(function(){
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						parent.layui.table.reload('AllTable',{
							page:{
								cuur:1
							},
							where:{
								UserId:$('#playerID').val()
							}
						});
					},1000);
				}
				$.ajax({
					url: 'pa/PlayerAdjustment',
					async: false,
					type:'post',
					data: {
						userId:data.field.userId,
						DifficultLevel:data.field.DifficultLevel,
						TargetFraction:number	
					},      //发送的是对象
					success: function(data){
						if(data == ""){
							layer.msg("操作成功",{icon:1});
							setTimeout(function(){
		                  		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		                          parent.layer.close(index); //再执行关闭 
		                          parent.layui.table.reload('AllTable',{
										page:{
											cuur:1
										},
										where:{
											UserId:$('#playerID').val()
										}
									});
		                  	},2000);
						}else{
							layer.msg(data,{icon:2});
						}
					}
				});
				return false;
			});
			
			$(document).on('click','#Transformation',function(){
				$.ajax({
					url: 'pa/NumberTransfrom',
					async: false,
					type:'post',
					data: {
						number:document.getElementById('TargetFraction').value
					},
					success: function(data){
						if(data != null){
							layer.open({
								  title: '转化成功'
								  ,content: data
								});
						}else{
							layer.msg(data,{icon:2});
						}
					}
				});
				return false;
			});
			
		});

		function sliderNumber() {
			//console.log(count); //打印全局变量，是生效的
			document.getElementById('slideNumber').value = count;
		}
	</script>
</body>
</html>
